﻿<!--[if ($smarty.session.PNSV_CART|@count) > 0]-->  
  <link rel="stylesheet" type="text/css" media="all" href="modules/IShopStore/pnjavascript/listcart/listcart.css" > 
  <script type="text/javascript"> 
    $(document).ready(function() {
//alert("Call this");
      /*
      $.get('modules/IShopStore/pnjavascript/jbasket/js/custom.js', function(data) {
        $('.cartPopup').html(data);
      });
      */
                          
      $('.increase').click(amount_inc);
      $('.decrease').click(amount_dec); 
           
                 
    });


          
    function amount_inc() {
    
      var valSplit	= (this.id).split("_");
      var productIDVal = valSplit[1];
      
      var price_val = parseInt($("#hidden_popup_price_list_"+productIDVal).text(), 10);
      var price_per_item_val = parseInt($("#hidden_popup_price_per_item_"+productIDVal).text(), 10);
      
      var popup_item_name = $("#popup_item_name_"+productIDVal).text();  
      
      var thumbname = $("#hidden_thumbname_"+productIDVal).text();   
      
      //Call addToCart function from php page
      var data = { 
                  module: "IShopStore", 
                  func: "addToCart", 
                  type: "ajax", 
                  id: productIDVal, 
                  thumbname : thumbname,
                  name : popup_item_name,
                  price : price_per_item_val
                 }; 
                                 
      $.ajax({  
              type: "POST",  
              url: "index.php",  
              data: data,   
              success: function(callback){
              
                //Increase amount              
                var amount_val = parseInt($("#popup_input_amount_"+productIDVal).val(), 10);
                $("#popup_input_amount_"+productIDVal).val(amount_val+1);   
                $("#cartside_amount_"+productIDVal).text(amount_val+1);                  
                
                //Increase price
                $("#hidden_popup_price_list_"+productIDVal).text(price_val+price_per_item_val);                       
                $("#popup_price_list_"+productIDVal).text(addCommas(price_val+price_per_item_val)+" บาท");                 
                $("#cartside_price_"+productIDVal).text(addCommas(price_val+price_per_item_val));
                
                
                //Increase summary price
                var summary_price = parseInt($("#hidden_popup_summary_price").text(), 10); 
                var new_summary_price = summary_price+price_per_item_val;                
                $("#hidden_popup_summary_price").text(new_summary_price);                               
                $("#popup_summary_price").text(addCommas(new_summary_price)+" บาท");                                   
                
              } 
      });
    }
     
    function amount_dec() {
      alert('-');
    } 
    
    function addCommas(nStr)
    {
      nStr += '';
      x = nStr.split('.');
      x1 = x[0];
      x2 = x.length > 1 ? '.' + x[1] : '';
      var rgx = /(\d+)(\d{3})/;
      while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
      }
      return x1 + x2;
    }
           
  </script>
  <table border="1" width="100%" class="cartPopup">
    <tr>
      <th colspan="5">ตระกร้าสินค้า</th>
    </tr>  
    <tr>
      <th>สินค้า</th>
      <th>ราคาต่อหน่วย</th>
      <th>จำนวน</th>
      <th colspan="2">ราคารวม</th>
    </tr>  
    <!--[assign var="tempSummary" value=0]-->        
    <!--[foreach from=$smarty.session.PNSV_CART item=item]-->     
        <tr>
          <td>
            <div id="hidden_ref_id_<!--[$item.id]-->" style="display:none;"><!--[$item.thumbname]--></div>   
  					<!--[$item.ref_id]-->                    
            <img src="<!--[$item.thumbname]-->" width="50"/>
            <div id="popup_item_name_<!--[$item.id]-->">
              <!--[$item.name]-->
            <div>            
          </td>
          <td>
            <div id="popup_price_per_item" align="right">
            <div id="hidden_popup_price_per_item_<!--[$item.id]-->" style="display:none;"><!--[$item.price_per_item]--></div>             
            <!--[$item.price_per_item|number_format:0]--> บาท         
            </div>
          </td>     
          <td class="amountTD" align="center">
            <div class="amount_control">
              <div class="increase" id="increase_<!--[$item.id]-->"></div>
              <div class="decrease" id="decrease_<!--[$item.id]-->"></div>
            </div>
            <input type="text" class="amount_box" id="popup_input_amount_<!--[$item.id]-->" value="<!--[$item.amount]-->">
          </td>            
          <td align="right">         
            <div id="hidden_popup_price_list_<!--[$item.id]-->" style="display:none;"><!--[$item.price]--></div>
            <div id="popup_price_list_<!--[$item.id]-->"><!--[$item.price|number_format:0]--> บาท</div>            
          </td>  
          <td>                         
            <a href="<!--[pnmodurl modname='IShopStore' type='ajax' func='deleteFromCart' id=$item.id]-->" onClick="return false;">
              <button class="delete_view_cart" id="popupDeleteProductID_<!--[$item.id]-->">ลบ</button>
           </a>  
          </td>                         
        </tr>  
        <!--[math assign="summary" equation="x+y"  x=$item.price y=$tempSummary]-->
        <!--[assign var="tempSummary" value=$summary]-->                       
    <!--[/foreach]-->	
        <tr>
          <td align="center" colspan="2">
            ราคาสินค้าทั้งหมด
          </td>               
          <td colspan="2" align="right">
            <div id="hidden_popup_summary_price" style="display:none;"><!--[$summary]--></div>  
            <div id="popup_summary_price"><!--[$summary|number_format:0]--> บาท</div>                      
          </td>  
          <td> 
          </td>                         
        </tr>
      </table>       	  
<!--[else]-->0<!--[/if]-->  